package com.example.systemtransfer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Settings;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button mybtn00,mybtn01,mybtn02,mybtn03,mybtn10,mybtn11,mybtn12,mybtn13,mybtn30,mybtn31;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.transfer);

        mybtn00 = (Button)findViewById(R.id.btnWeb);
        mybtn01 = (Button)findViewById(R.id.btnMap);
        mybtn02 = (Button)findViewById(R.id.btnPhone);
        mybtn03 = (Button)findViewById(R.id.btnCall);
        mybtn10 = (Button)findViewById(R.id.btnUnload);
        mybtn11 = (Button)findViewById(R.id.btnInstall);
        mybtn12 = (Button)findViewById(R.id.btnEmall);
        mybtn13 = (Button)findViewById(R.id.btnMassage);
        mybtn30 = (Button)findViewById(R.id.btnMusic);
        mybtn31 = (Button)findViewById(R.id.btnCamera);

        //打开默认浏览器
        mybtn00.setOnClickListener(v->{
            Intent intent = new Intent();//意图
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse("http://www.baidu.com"));
            startActivity(intent);
        });
        //打开地图
        mybtn01.setOnClickListener(v->{
            String encodedName = Uri.encode("长江大学东校区");
            Uri locationUri = Uri.parse("geo:30.332500,112.215553?q="+encodedName);
            Intent intent = new Intent(Intent.ACTION_VIEW, locationUri);
            startActivity(intent);
        });

        //打开电话界面
        mybtn02.setOnClickListener(v->{
            Uri telUri = Uri.parse("tel:10086");
            Intent intent=new Intent(Intent.ACTION_DIAL,telUri);
            startActivity(intent);
        });

        //直接拨打电话
        mybtn03.setOnClickListener(v->{
            Uri telUri = Uri.parse("tel:10086");
            Intent intent=new Intent(Intent.ACTION_CALL,telUri);
            //需要添加Permission权限
            if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE)== PackageManager.PERMISSION_GRANTED) {
                startActivity(intent);
            }
        });
        //卸载
        mybtn10.setOnClickListener(v->{
            String packageName = getPackageName();//获取当前应用
            Uri unloadUri = Uri.fromParts("package",packageName,null);
            Intent intent=new Intent(Intent.ACTION_DELETE,unloadUri);
            startActivity(intent);
        });
        //安装
        mybtn11.setOnClickListener(v->{
            String packageName = getPackageName();
            Uri installUri = Uri.fromParts("package",packageName,null);
            Intent intent=new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,installUri);
            startActivity(intent);
        });
        //打开邮件页面
        mybtn12.setOnClickListener(v->{
            Uri emailUri = Uri.parse("mailto:2459622492@qq.com");
            Intent intent=new Intent(Intent.ACTION_SENDTO,emailUri);
            startActivity(intent);
        });
        //发短信
        mybtn13.setOnClickListener(v->{
            String phoneNumber="10086";
            String message = "11";
            Uri messageUri = Uri.parse("smsto:"+phoneNumber);
            Intent intent=new Intent(Intent.ACTION_SENDTO,messageUri);
            intent.putExtra("sms_body",message);
            startActivity(intent);
        });
        //打开系统音乐
        mybtn30.setOnClickListener(v->{
            Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
            startActivity(intent);
        });
        //打开相机
        mybtn31.setOnClickListener(v->{
            Intent intent;
            intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 101);
        });

    }
}
